import logging

import requests


class Test11():
    uid = ""
    sid = ""
    cid = ""
    aid = ""

    def setup_method(self):
        print("开始")

    def teardown_method(self):
        print("清理环境")

    def test_login(self):
        url = "http://10.59.9.18/small/user/v1/login"
        body = {"phone": "13811033965", "pwd": "123456Aa"}
        headers = {"Content-Type": "application/json"}
        r = requests.post(url=url, headers=headers, json=body)
        Test11.uid = r.json()['result']['userId']
        Test11.sid = r.json()['result']['sessionId']
        print(r.json())
        logging.info("weidudiansanglog.txt")
        assert r.json()['result']['nickName'] == '韩坤1号'
        # 收货地址

    def test_address(self):
        url = "http://10.59.9.18/small/user/verify/v1/receiveAddressList"
        headers = {"userId": str(Test11.uid), "sessionId": Test11.sid}
        r = requests.get(url=url, headers=headers)
        Test11.aid = r.json()['result'][0]['id']
        print(r.json())
        logging.info("weidudiansanglog.txt")
        assert '北京 海淀区 dwasaaa' in r.text

    def test_order(self):
        url = "http://10.59.9.18/small/commodity/v1/commodityList"
        r = requests.get(url=url)
        Test11.cid = r.json()['result']['rxxp']['commodityList'][0]['commodityId']
        print(r.json())
        logging.info("weidudiansanglog.txt")
        assert r.status_code == 200

    def test_order_xq(self):
        url = "http://10.59.9.18/small/commodity/v1/findCommodityDetailsById"
        headers = {"userId": str(Test11.uid), "sessionId": Test11.sid}
        body = {"commodityId": Test11.cid}
        r = requests.get(url=url, headers=headers, params=body)
        print(r.json())
        logging.info("weidudiansanglog.txt")
        assert '女鞋' in r.text

    def test_order_create(self):
        url = "http://10.59.9.18/small/order/verify/v1/createOrder"
        headers = {"userId": str(Test11.uid), "sessionId": Test11.sid}
        body = {"orderInfo": {"commodityId": Test11.cid, "amount": 1}, "totalPrice": 189, "addressId": Test11.aid}
        r = requests.post(url=url, headers=headers, data=body)
        print(r.json())
        logging.info("weidudiansanglog.txt")
        assert r.status_code == 200
